package com.CoreryBlack.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Slf4j
@Component
@Aspect
public class MyAspect5 {
    //前置通知
    @Before("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
    public void before(JoinPoint joinPoint){
        log.info("MyAspect4 -> before ...");

        //1. 获取目标类的类名
        log.info("目标类的类名: {}", joinPoint.getTarget().getClass());

        //2. 获取原始方法的签名
        log.info("原始方法的签名: {}", joinPoint.getSignature());

        //3. 获取方法名
        log.info("获取方法名: {}", joinPoint.getSignature().getName());

        //4. 获取方法运行时的参数
        Object[] args = joinPoint.getArgs();
        log.info("方法运行时的参数 : {}", Arrays.toString(args));
    }




    //原始方法运行前 - 原始方法 - 后
    @Around("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        log.info("MyAspect1 ... around before ...");

        Object result = pjp.proceed();

        log.info("MyAspect1 ... around before ...");
        return result;
    }
}
